package com.zhongshengnetwork.rightbe.dbservice;

import com.zhongshengnetwork.rightbe.CustomApplication;
import com.zhongshengnetwork.rightbe.common.CommonUtils;
import com.zhongshengnetwork.rightbe.dbmodel.LangDatadbModel;
import com.zhongshengnetwork.rightbe.dbmodel.SyncInfodbModel;

import org.xutils.DbManager;
import org.xutils.ex.DbException;
import org.xutils.x;

/**
 * Created by luojingxing on 2018/6/26.
 */

public class LangDatadbService {
    //插入或者更新数据
    public static boolean saveOrUpdate(LangDatadbModel model){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.saveOrUpdate(model);
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //设置gamedata
    public static boolean setGameData(String gamedata){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            LangDatadbModel model = db.findById(LangDatadbModel.class,1);
            if (model != null){
                model.setGamedata(gamedata);
                db.saveOrUpdate(model);
            }
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //获取gamedata
    public static String getGameData(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            if (db.findById(LangDatadbModel.class,1) != null)
                return db.findById(LangDatadbModel.class,1).getGamedata();
            return "0";
        } catch (DbException e) {
            e.printStackTrace();
            return "0";
        }
    }

    //设置caredata
    public static boolean setCareData(String caredata){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            LangDatadbModel model = db.findById(LangDatadbModel.class,1);
            if (model != null){
                model.setCaredata(caredata);
                db.saveOrUpdate(model);
            }
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //获取caredata
    public static String getCareData(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            if (db.findById(LangDatadbModel.class,1) != null)
                return db.findById(LangDatadbModel.class,1).getCaredata();
            return "0";
        } catch (DbException e) {
            e.printStackTrace();
            return "0";
        }
    }

    //设置hotdata
    public static boolean setHotData(String hotdata){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            LangDatadbModel model = db.findById(LangDatadbModel.class,1);
            if (model != null){
                model.setHotdata(hotdata);
                db.saveOrUpdate(model);
            }
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //获取hotdata
    public static String getHotData(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            if (db.findById(LangDatadbModel.class,1) != null)
                return db.findById(LangDatadbModel.class,1).getHotdata();
            return "0";
        } catch (DbException e) {
            e.printStackTrace();
            return "0";
        }
    }

    //设置latestdata
    public static boolean setLatestData(String latestdata){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            LangDatadbModel model = db.findById(LangDatadbModel.class,1);
            if (model != null){
                model.setLatestdata(latestdata);
                db.saveOrUpdate(model);
            }
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //获取latestdata
    public static String getLatestData(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            if (db.findById(LangDatadbModel.class,1) != null)
                return db.findById(LangDatadbModel.class,1).getLatestdata();
            return "0";
        } catch (DbException e) {
            e.printStackTrace();
            return "0";
        }
    }

    //设置circledata
    public static boolean setCircleData(String circledata){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            LangDatadbModel model = db.findById(LangDatadbModel.class,1);
            if (model != null){
                model.setCircledata(circledata);
                db.saveOrUpdate(model);
            }
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }
    }

    //获取circledata
    public static String getCircleData(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            if (db.findById(LangDatadbModel.class,1) != null)
                return db.findById(LangDatadbModel.class,1).getCircledata();
            return "0";
        } catch (DbException e) {
            e.printStackTrace();
            return "0";
        }
    }


    //删除数据
    public static boolean deleteModel(){
        DbManager db = x.getDb(CustomApplication.daoConfig);
        try {
            db.delete(SyncInfodbModel.class);
            return true;
        } catch (DbException e) {
            e.printStackTrace();
            return false;
        }

    }
}
